package top.xchch.crud.dao;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import top.xchch.crud.entity.Department;
import top.xchch.crud.entity.Employee;

@Component
public class EmployeeDao {
	
	private static Map<Integer, Employee> employees = null;
	
	@Autowired
	private DepartmentDao departmentDao;
	
	static {
		employees = new HashMap<>();
		
		employees.put(1001, new Employee(1001, "E-AA", "aa@atguigu.com", "1", 101));
		employees.put(1002, new Employee(1002, "E-BB", "bb@atguigu.com", "1", 101));
		employees.put(1003, new Employee(1003, "E-CC", "cc@atguigu.com", "1", 102));
		employees.put(1004, new Employee(1004, "E-DD", "dd@atguigu.com", "1", 101));
		employees.put(1005, new Employee(1005, "E-EE", "ee@atguigu.com", "1", 103));
	}
	
	private Integer initId = 1006;
	
	public void save(Employee employee) {
		if (employee.getId() == null) {
			employee.setId(initId++);
		}
		employees.put(employee.getId(), employee);
	}
	
	public Collection<Employee> getAll(){
		return employees.values();
	}
	
	public Employee get(Integer id){
		return employees.get(id);
	}
	
	public void delete(Integer id) {
		employees.remove(id);
	}
}
